package lucene.server.web.config;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;

import javax.annotation.PostConstruct;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SystemConfig{

    private static Map<String, String> systemParams = new HashMap<>();
    @PostConstruct
    public static void init() {
        try
        {
            List<Entity> list = Db.use().findAll("setting");
            list.forEach(entity -> {
                systemParams.put(entity.getStr("param"),entity.getStr("value"));
            });
        }catch (SQLException e)
        {

        }
    }
   public static String getParam(String key)
   {
       return systemParams.get(key);
   }
   public static String getWebRoot()
   {
        return systemParams.get("webRoot");
   }
    public static String getIndexRoot()
    {
        if (systemParams.get("indexRoot")==null)
        {
            init();
        }
        return systemParams.get("indexRoot");
    }
    //是否处理blob字段
    public static boolean getDealBlob()
    {
        if (Boolean.parseBoolean(systemParams.get("dealBlob")))
        {
            return true;
        } else{
            return false;
        }
    }



}
